package net.seriousinc.SeriousMobile;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;

public class LoginActivity extends Activity {

	 @Override
	 public void onCreate(Bundle savedInstanceState) {
		 	super.onCreate(savedInstanceState);
		 	if(ZenoChatActivity.active)
		 	{
		 		Intent i = new Intent();
				 i.setClass(this, SeriousMobileActivity.class);
				 startActivity(i);
				 finish();
		 	}
		 	else
		 	{
			 	setContentView(R.layout.login);
			 	SharedPreferences settings = getSharedPreferences("SeriousMobile", 0);
			 	
			 	if(settings.contains("nick"))
			 		((EditText)findViewById(R.id.nickField)).setText(settings.getString("nick", ""));
			 	if(settings.contains("nickserv"))
			 		((EditText)findViewById(R.id.nickserv)).setText(settings.getString("nickserv", ""));
		 	}
		 	
	 }
	 
	 public void login(View v)
	 {
		 String nick = ((EditText)findViewById(R.id.nickField)).getText().toString();
		 String nickserv = ((EditText)findViewById(R.id.nickserv)).getText().toString();
		 
		 if(nick.length() != 0)
		 {
			 
		 
		 Intent i = new Intent();
		 i.setClass(this, SeriousMobileActivity.class);
		 i.putExtra("nick", nick);
		 i.putExtra("nickserv", nickserv);
		
		 SharedPreferences settings = getSharedPreferences("SeriousMobile", 0);
		 SharedPreferences.Editor edit = settings.edit();
		 
		 edit.putString("nick", nick);
		 edit.putString("nickserv", nickserv);
		 edit.commit();

		 
		 
		 startActivity(i);
		 
		 
		 finish();
		 }
	 }
	 
	 @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
    	super.onConfigurationChanged(newConfig);
    }
}
